package grape.crm.service.relationdetail.api;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import grape.common.service.trans.ITransService;
import grape.crm.service.relationdetail.po.RelationDetail;
import grape.common.service.common.IBaseService;

/**
 * <p>
 * 客户关系具体字典表 服务类
 * </p>
 *
 * @author yangwei
 * @since 2020-09-14
 */
public interface IRelationDetailService extends IBaseService<RelationDetail> , ITransService<String,String> {

    public static final String trans_relation_detail_name = "trans_relation_detail_name";
    public static final String trans_relation_detail_code = "trans_relation_detail_code";

    /**
     * 判断编码是否已存在
     * @param code
     * @return
     */
    default boolean existCode(String code){
        assertParamNotEmpty(code,"code 不能为空");
        RelationDetail relation = new RelationDetail();
        relation.setCode(code);
        int r = count(Wrappers.query(relation));
        return r > 0;
    }
    @Override
    default boolean support(String type){
        return isEqualAny(type,trans_relation_detail_code, trans_relation_detail_name);
    }

    @Override
    default String trans(String type, String key){
        RelationDetail po = getById(key);
        if (po != null) {
            if (isEqual(type,trans_relation_detail_name)) {
                return po.getName();
            }else if (isEqual(type,trans_relation_detail_code)) {
                return po.getCode();
            }
        }
        return null;
    }
}
